package com.beta.auth.aop;

import com.beta.cat.aop.ApiBaseAspect;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @description:
 * @author: liujin
 * @createDate: 2021/4/29
 * @version: 1.0
 */
@Aspect
@Order(0)
@Component
public class ApiLogAopAspect extends ApiBaseAspect {

    @Pointcut("execution(* com.beta.auth.controller..*.*(..))")
    public void pointCut() {
    }

    @Around(value = "pointCut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = null;
        if (requestAttributes != null) {
            request = (requestAttributes).getRequest();
        }

        return around(joinPoint, request, false);
    }
}
